<template>
    <div>
      <h1>登录</h1>
      <table class="table table-bordered">
        <tbody class="bg-info">
            <tr>
                <td align="right">账号</td>
                <td>
                    <input type="text" v-model="info.UserName">
                </td>
            </tr>
            <tr>
                <td align="right">密码</td>
                <td>
                    <input type="password" v-model="info.UserPwd">
                </td>
            </tr>
            <tr>
                <td align="right"></td>
                <td>
                    <input type="button" value="登录" class="btn btn-primary" @click="ok">
                </td>
            </tr>
        </tbody>
      </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from 'vue';
import axios from 'axios';
import moment from 'mooment';
import{useRouter,useRoute} from 'vue-router';
const router=useRouter();
const route=useRoute();

import {useStore} from '@/stores/user';
const a=useStore();

let info:any=reactive({
    UserName:'',
    UserPwd:'',
})

const ok=()=>{
    if(info.UserName==''){
        alert('账号不能为空');
        return;
    }
    if(info.UserPwd==''){
        alert('密码不能为空');
        return;
    }
    axios({
        url:'https://localhost:7268/api/Login/UserLogin',
        method:'get',
        params:info,
    })
    .then(res=>{
        console.log(res);
        if(res.data>0){
            alert('登录成功');
            a.userinfo=res.data;
            router.push('/loginlist');
        }
        if(res.data==-1){
            alert('账号不存在');
            return;
        }
        if(res.data==-2){
            alert('密码错误');
            return;
        }
        
    })
}
</script>

<style scoped>

</style>